GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

http.createServer   A
last analyzed

Complexity

Conditions 3
Paths 5

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
nc 5
dl 0
loc 23
rs 9.0856
nop 1
1
var raml2html = require('raml2html');
2
var chalk = require('chalk');
3
var emoji = require('node-emoji');
4
var fs = require('fs');
5
var path = require('path');
6
var http = require('http');
7
var url = require('url');
8
9
var enviroment = process.env.npm_package_config_enviroment;
10
11
var apiDir = path.join(__dirname, '../../api/');
12
var ramlFile = path.join(__dirname, '../../api/api.raml');
13
14
process.stdout.write(chalk.gray(emoji.emojify('[  ] Server Documentazione API (' + enviroment + ") from "+ ramlFile))+ "\n");
15
16
var server = http.createServer(function (req, res) {
17
  // console.log(`${req.method} ${req.url}`);
18
  process.stdout.write(chalk.gray(emoji.emojify('[  ] Request ' + `${req.method} ${req.url}`))+ "\n");
19
20
  // parse URL
21
  var parsedUrl = url.parse(req.url);
22
  // extract URL path
23
  let pathname = `${parsedUrl.pathname}`;
24
  // based on the URL path, extract the file extention. e.g. .js, .doc, ...
25
  var ext = path.parse(pathname).ext;
26
  // maps file extention to MIME types
27
  var mimeType = {
28
    '.html': 'text/html',
29
    '.json': 'application/json'
30
  };
31
  let pathnameFull = path.normalize(apiDir + pathname);
32
33
  if ( pathname == '/end' ) {
34
    // console.log('/end');
35
    res.statusCode = '204';
36
    res.end();
37
    process.exit(0);
0 ignored issues
show
Compatibility Debugging Code Best Practice introduced by
Use of process.exit() is discouraged as it will potentially stop the complete node.js application. Consider quitting gracefully instead by throwing an Error.
Loading history...
38
  }
39
40
  fs.exists(pathnameFull, function (exist) {
41
    if(!exist) {
42
      // if the file is not found, return 404
43
      res.statusCode = 404;
44
      res.end(`File ${pathname} not found!`);
45
      return;
46
    }
47
    // if is a directory, then look for index.html
48
    if (fs.statSync(pathnameFull).isDirectory()) {
49
      pathnameFull += '/index.html';
50
    }
51
    // read file from file system
52
    fs.readFile(pathnameFull, function(err, data){
53
      if(err){
54
        res.statusCode = 500;
55
        res.end(`Error getting the file: ${err}.`);
56
      } else {
57
        // if the file is found, set Content-type and send data
58
        res.setHeader('Content-type', mimeType[ext] || 'text/plain' );
59
        res.end(data);
60
      }
61
    });
62
  });
63
});
64
65
server.listen(9999, '127.0.0.1');
66
67
process.stdout.write(chalk.gray(emoji.emojify('[  ] Server listening ' + apiDir + ' on port ' + 9999))+ "\n");
68